package cn.doctor.assistant.pad.ui.hudong;


import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.blunderer.materialdesignlibrary.fragments.ViewPagerWithTabsFragment;
import com.blunderer.materialdesignlibrary.handlers.ViewPagerHandler;

/**
 * Created by jiaolf on 2016/3/25.
 * <p/>
 * 互动-联系人
 */
public class ContactsFragment extends ViewPagerWithTabsFragment implements ViewPager.OnPageChangeListener {
    // 会话列表
    ChatHistoryFragment chatHistoryFragment;
    // 联系人列表
    ContactsListFragment contactsListFragment;

    @Override
    protected boolean expandTabs() {
        return true;
    }

    @Override
    public ViewPagerHandler getViewPagerHandler() {
        chatHistoryFragment = new ChatHistoryFragment();
        contactsListFragment = new ContactsListFragment();

        return new ViewPagerHandler(getActivity())
                .addPage("会话", chatHistoryFragment)
                .addPage("联系人", contactsListFragment);
    }

    public void onRedisplay() {
        if (chatHistoryFragment != null) {
            chatHistoryFragment.onRedisplay();
        }
    }

    @Override
    public int defaultViewPagerPageSelectedPosition() {
        return 0;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setOnPageChangeListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
        if (position == 0 && chatHistoryFragment != null) {
            chatHistoryFragment.onRedisplay();
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }
}
